const express = require('express');
 
let router = express.Router();
const bodyParser = require('body-parser')

router.use(bodyParser.json());
router.use(bodyParser.urlencoded({extended: false}));
 
const mysql = require('mysql');


//实现本地链接
var connection = mysql.createConnection({
    host: 'localhost',
    user: 'root',
    password: 'root',
    database: 'test'
})


router.get('/list/:author', function (req, res) {
	res.status(200);
	connection.query('SELECT * FROM t_chapter where author = ?' , req.params.author, function (error, results, fields) {
	        if (error) 
	            throw error;
	        res.json(results);
	        console.log('results is:', results);
	    });
});
 
router.get('music/:id', function (req, res) {
    res.send(`${req.params.id} 订单信息`);
});
 
//导出该路由
module.exports = router;